home *** CD-ROM | disk | FTP | other *** search
- #include "ToolSort.h"
- /*=========================================================================
- Module: bubble
-
- Purpose: Sort array in ascending order.
-
- Notes: Sorts and array in increasing order. This algorithm has a
- complexity of n^2.
-
- Uses: Function Comp( *type, *type) and function Swap( *type, *type).
-
- Returns: selLine
-
- =========================================================================*/
- Bubble(elem, big, num, comp, swap)
- void *elem; /* Array of elem pointers*/
- int big; /* size of the data elements */
- int num; /* No. elem*/
- int (*comp)(); /* pointer to comparison function */
- int (*swap)(); /* pointer to swap function */
- {
- register char *b = elem;
- register int k,i;
-
- for (k=1; k<=num-1; k++)
- {
- for (i=0; i<num-k; i++)
- {
- if ( (*comp)(b+i*big, b+(i+1)*big) > 0)
- (*swap)(b+i*big, b+(i+1)*big);
- }
- }
- }
-